#ifndef __TURRET_H__
#define __TURRET_H__
#include "Model.h"
#include "glm/glm.h"


class TurretBase
{
private:
	Model* model;
public:
	TurretBase(Model* model)
	{
		this->model = model;
	}
	void Draw()
	{
		glmDraw(model->get_model(), GL_SMOOTH);
	}
};
class TurretBarrrel
{
private:
	Model* model;
public:
	TurretBarrrel(Model* model)
	{
		this->model = model;
	}
	void Draw()
	{
		glColor3f(1, 1, 1);
		glmDraw(model->get_model(), GL_SMOOTH);
	}
};
class Turret
{
private:
	float x, y, z;
	float scale_factor;
	float width;
	float height;
	float depth;
	TurretBase* base;
	TurretBarrrel* barrrel;

	float rotate_angle;
	float lift_angle;
public:
	Turret(float x, float y, float z, float scale_factor, Model* base_model, Model* barrrel_model)
	{
		this->x = x;
		this->y = y;
		this->z = z;
		this->scale_factor = scale_factor;

		base = new TurretBase (base_model);
		barrrel = new TurretBarrrel (barrrel_model);

		rotate_angle = 0;
		lift_angle = 0;

		this->width = base_model->get_width() * scale_factor;
		this->height = base_model->get_height() * scale_factor;
		this->depth = base_model->get_depth() * scale_factor;
	}
	void Rotate ( float delta_rotate, float delta_lift )
	{
		rotate_angle += delta_rotate;
		if ( rotate_angle > 180 )
			rotate_angle = 180;
		if ( rotate_angle < -180 )
			rotate_angle = -180;
		lift_angle -= delta_lift;
		if ( lift_angle > 0 )
			lift_angle = 0;
		if ( lift_angle < -90 )
			lift_angle = -90;
	}
	virtual void Draw()
	{
		glPolygonMode(GL_FRONT, GL_LINE);
		glPolygonMode(GL_BACK, GL_LINE);

		glPushMatrix();
		glTranslatef(x,y + height / 2,z);
		glPushMatrix();
		glScalef(scale_factor, scale_factor, scale_factor);
		glRotatef(rotate_angle - 90, 0,1,0 );
		base->Draw();
		glPopMatrix();
		
		glRotatef(rotate_angle - 90, 0,1,0 );
		glRotatef(lift_angle, 0,0,1 );
		
		glTranslatef(-160, -5, 10);
		
		//glTranslatef(-110*sin(lift_angle), 110*cos(lift_angle), 0);
		glScalef(scale_factor, scale_factor, scale_factor);
		barrrel->Draw();
		glPopMatrix();
	}
};

#endif